package adventure.commands;

import adventure.*;
import player.*;

/**
 *
 * @author Michael Hanns
 *
 */
public class SetPassword extends AbstractCommand {

    public SetPassword(Adventure a) {
        super(a, new String[]{"PASSWORD", "SETPASSWORD", "CHANGEPASSWORD"});
    }

    @Override
    public String validateAndExecute(Player p, String[] args) {
        if (args.length == 1) {
            return "Change your password to what?";
        } else if (args.length == 4) {
            if (((PlayerEdit) p).getPassword().equals(args[1])) {
                if (args[2].equals(args[3])) {
                    ((PlayerEdit)p).setPassword(args[2]);
                    return "Your password has been updated successfully.";
                } else {
                    return "New password confirmation does not match. Your password has not been changed.";
                }
            } else {
                return "Incorrect password. Your password has not been changed.";
            }
        } else {
            return "Syntax: password <oldpassword> <newpassword> <newpassword>";
        }
    }
}
